package Aleehot100;

/**
 * ClassName: c072
 * Package: Aleehot100
 * Description:739. 每日温度
 *
 * @Author BCXJ
 * @Create 2025/8/17 15:44
 * @Version 1.0
 * @Since 1.0
 */
public class c072 {
    public static void main(String[] args) {

    }

    static int[] stack = new int[100000];
    static int r = 0; // 栈的边界
    public static int[] dailyTemperatures(int[] temperatures) {
        int n = temperatures.length;
        r = 0;
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            // 栈顶元素 小于当前下标的元素
            while(r > 0 && temperatures[stack[r - 1]] < temperatures[i]) {
                res[stack[-- r]] = i - stack[r];
            }
            stack[r ++] = i;
        }
        return res;
    }

}
